Merge "mediawiki.special.upload.js: Remove spinner in .always() instead of .done()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 25 Apr 2016 17:15:16 +0000 (17:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 25 Apr 2016 17:15:16 +0000 (17:15 +0000)
1  2 
resources/src/mediawiki.special/mediawiki.special.upload.js

                },
  
                timeout: function () {
 -                      var $spinnerDestCheck;
 +                      var $spinnerDestCheck, title;
                        if ( !ajaxUploadDestCheck || this.nameToCheck === '' ) {
                                return;
                        }
                        $spinnerDestCheck = $.createSpinner().insertAfter( '#wpDestFile' );
 +                      title = mw.Title.newFromText( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file );
  
                        ( new mw.Api() ).get( {
 +                              formatversion: 2,
                                action: 'query',
 -                              titles: ( new mw.Title( this.nameToCheck, mw.config.get( 'wgNamespaceIds' ).file ) ).getPrefixedText(),
 +                              // If title is empty, user input is invalid, the API call will produce details about why
 +                              titles: title ? title.getPrefixedText() : this.nameToCheck,
                                prop: 'imageinfo',
 -                              iiprop: 'uploadwarning',
 -                              indexpageids: true
 +                              iiprop: 'uploadwarning'
                        } ).done( function ( result ) {
 -                              var resultOut = '';
 -                              if ( result.query ) {
 -                                      resultOut = result.query.pages[ result.query.pageids[ 0 ] ].imageinfo[ 0 ];
 +                              var
 +                                      resultOut = '',
 +                                      page = result.query.pages[ 0 ];
 +                              if ( page.imageinfo ) {
 +                                      resultOut = page.imageinfo[ 0 ].html;
 +                              } else if ( page.invalidreason ) {
 +                                      resultOut = mw.html.escape( page.invalidreason );
                                }
-                               $spinnerDestCheck.remove();
                                uploadWarning.processResult( resultOut, uploadWarning.nameToCheck );
+                       } ).always( function () {
+                               $spinnerDestCheck.remove();
                        } );
                },
  
                processResult: function ( result, fileName ) {
 -                      this.setWarning( result.html );
 -                      this.responseCache[ fileName ] = result.html;
 +                      this.setWarning( result );
 +                      this.responseCache[ fileName ] = result;
                },
  
                setWarning: function ( warning ) {
                        $spinnerLicense = $.createSpinner().insertAfter( '#wpLicense' );
  
                        ( new mw.Api() ).get( {
 +                              formatversion: 2,
                                action: 'parse',
                                text: '{{' + license + '}}',
                                title: $( '#wpDestFile' ).val() || 'File:Sample.jpg',
                                prop: 'text',
                                pst: true
                        } ).done( function ( result ) {
-                               $spinnerLicense.remove();
                                uploadLicense.processResult( result, license );
+                       } ).always( function () {
+                               $spinnerLicense.remove();
                        } );
                },
  
                processResult: function ( result, license ) {
 -                      this.responseCache[ license ] = result.parse.text[ '*' ];
 +                      this.responseCache[ license ] = result.parse.text;
                        this.showPreview( this.responseCache[ license ] );
                },
  
  
                                        $( '#mw-upload-thumbnail .fileinfo' ).text( info );
                                };
 +                              img.onerror = function () {
 +                                      // Can happen for example for invalid SVG files
 +                                      clearPreview();
 +                              };
                                img.src = dataURL;
                        }, mw.config.get( 'wgFileCanRotate' ) ? function ( data ) {
                                try {